package com.example.chatzsyproject.utils;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.TextView;

import com.example.chatzsyproject.R;
import com.example.chatzsyproject.callback.DialogCallBack;
import com.fanwe.lib.dialog.impl.SDDialogConfirm;

import java.util.Calendar;

public class UtilsView {
    /**
     * 纯文字对话框
     *
     * @param activity
     * @param dialogCallBack
     */
    public static void showSendCardToChatDialog(String s, String ok, String no, Activity activity, DialogCallBack dialogCallBack) {
        final SDDialogConfirm dialog = new SDDialogConfirm(activity);
        View view = LayoutInflater.from(activity).inflate(R.layout.dialog_sendcardtochat, null);
        ((TextView) view.findViewById(R.id.tv_content)).setText(s);
        ((TextView) view.findViewById(R.id.tv_ok)).setText(ok);
        ((TextView) view.findViewById(R.id.tv_no)).setText(no);
        view.findViewById(R.id.ok).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialogCallBack.succ("");
                dialog.dismiss();
            }
        });
        view.findViewById(R.id.no).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialogCallBack.error("");
                dialog.dismiss();
            }
        });
        dialog.setContentView(view);
        dialog.setCanceledOnTouchOutside(true);
        dialog.show();
    }

    /**
     * 带输入框得对话框
     *
     * @param ok
     * @param no
     * @param activity
     * @param dialogCallBack
     */
    public static void showEdittextDialog(String ok, String no, Activity activity, DialogCallBack dialogCallBack) {
        final SDDialogConfirm dialog = new SDDialogConfirm(activity);
        View view = LayoutInflater.from(activity).inflate(R.layout.dialog_edittext, null);
        ((TextView) view.findViewById(R.id.tv_ok)).setText(ok);
        ((TextView) view.findViewById(R.id.tv_no)).setText(no);
        view.findViewById(R.id.ok).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialogCallBack.succ(((EditText) view.findViewById(R.id.et_content)).getText().toString());
                dialog.dismiss();
            }
        });
        view.findViewById(R.id.no).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialogCallBack.error("");
                dialog.dismiss();
            }
        });
        dialog.setContentView(view);
        dialog.setCanceledOnTouchOutside(true);
        dialog.show();
    }

    /**
     * 时间选择器对话框
     *
     * @param activity
     * @param themeResId
     * @param calendar
     */
    public static void showDatePickerDialog(Activity activity, int themeResId, Calendar calendar) {
        // 直接创建一个DatePickerDialog对话框实例，并将它显示出来
        new DatePickerDialog(activity, themeResId, new DatePickerDialog.OnDateSetListener() {
            // 绑定监听器(How the parent is notified that the date is set.)
            @Override
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                // 此处得到选择的时间，可以进行你想要的操作
                Log.e("zsy", "data=" + "您选择了：" + year + "年" + (monthOfYear + 1) + "月" + dayOfMonth + "日");
            }
        }
                // 设置初始日期
                , calendar.get(Calendar.YEAR)
                , calendar.get(Calendar.MONTH)
                , calendar.get(Calendar.DAY_OF_MONTH)).show();
    }
}
